package com.greet.controller.admin;


import com.greet.constant.RedisDataKeys;
import com.greet.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")

public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态为:\"{}\"", status == 1 ? "营业中" : "打样中");
        redisTemplate.opsForValue().set(RedisDataKeys.SHOP_STATUS, status);
        return Result.success();
    }

    @GetMapping("/status")
    public Result getStatus(){
        Integer shopStatus = (Integer)redisTemplate.opsForValue().get(RedisDataKeys.SHOP_STATUS);
        log.info("获取营业状态\"{}\"",  shopStatus == 1 ? "营业中" : "打烊中");
        return Result.success(shopStatus);
    }
}
